import { defineStore } from "pinia";
import { PageType } from "@/interface/index";
import tabbarList from "@/router/tabbar";
let cachedViews: Array<string> = [];
tabbarList.forEach((item) => {
  if (item.mate.isCached) {
    cachedViews.push(item.name);
  }
});
interface TabbarStoreType {
  list: Array<PageType>;
  activeIndex: number;
  cachedViews: Array<string>;
}

const useTabbarStore = defineStore({
  id: "tabbar",
  state: (): TabbarStoreType => {
    return {
      list: tabbarList,
      activeIndex: 0,
      cachedViews: cachedViews,
    };
  },
  getters:{
    currentPageTitle():string{

      let title= this.list[this.activeIndex].mate.title
      return title
    }
  },
  actions: {
    /**
     * 设置list
     * @param list
     */
    setList(list: Array<PageType>) {
      this.list = list;
    },

    /**
     * 设置消息数量
     * @param index
     * @param num
     */
    setMsgNum(index: number, num: number) {
      if (this.list[index] && this.list[index].mate) {
        this.list[index].mate.msgNum = num;
      }
    },
  },
});

export default useTabbarStore;
